import React, { Component } from 'react'
import { Button, message, Upload } from 'antd'
import './index.scss'
import { connect } from 'react-redux'
import userImgAction from '../../../redux/action/userImgAction'
class Index extends Component {
    state = {
        name: 'file',
        action: `/cpi/userInfo/loadImg?username=${this.props.username}`,
        headers: {
          authorization: 'authorization-text',
        }
    }
    onChange = (info) => {
        if (info.file.status !== 'uploading') {
            // console.log(info.fileList[0].response.data.userList);
            let img=info.fileList[0].response.data.userList.path
            this.props.userImgAction(img)
        }

        if (info.file.status === 'done') {
            message.success(`上传成功`);
        } else if (info.file.status === 'error') {
            message.error(`上传失败`);
        }
    }
    render() {
        let {title} = this.props
        return (
            <>
                <Upload {...this.state} onChange={this.onChange}>
                    <Button className='btn'>{title}</Button>
                </Upload>
            </>
        )
    }
}
export default connect(
    state=>({
        username:state.login
    }),
    {
        userImgAction
    }
)(Index)